package com.hermes.biz.dao.evt.impl;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.hermes.biz.common.model.evt.EvtDO;
import com.hermes.biz.dao.evt.EvtDAO;
import com.hermes.biz.dao.user.impl.UserDAOImpl;

public class EvtDAOImpl extends SqlMapClientDaoSupport implements EvtDAO{

	private Logger log = Logger.getLogger(UserDAOImpl.class);

	@SuppressWarnings("unchecked")
	public List<EvtDO> getEvtByCreateUserId(long createUserId) {
		try {
			return getSqlMapClientTemplate().getSqlMapClient().queryForList("getEvtByCreateUserId",null);
		} catch (SQLException e) {
			log.error(e);
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<EvtDO> getEvtByMsgType(long msgType) {
		try {
			return getSqlMapClientTemplate().getSqlMapClient().queryForList("getEvtByMsgType",null);
		} catch (SQLException e) {
			log.error(e);
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<EvtDO> getEvtByCreateTime(Date createTime) {
		try {
			return getSqlMapClientTemplate().getSqlMapClient().queryForList("getEvtByCreateTime",null);
		} catch (SQLException e) {
			log.error(e);
		}
		return null;
	}

	public EvtDO getEvtByEvtId(long evtId) {
		try {
			return (EvtDO)getSqlMapClientTemplate().getSqlMapClient().queryForObject("EvtDAO.getEvtByEvtId",evtId);
		} catch (SQLException e) {
			log.error(e);
		}
		return null;
	}

	public void saveEvt(EvtDO evt) {
		try {
			this.getSqlMapClientTemplate().getSqlMapClient().insert("EvtDAO.insertEvt",evt);
		} catch (SQLException e) {
			log.error(e);
		}		
	}

	public void deleteEvtByCreateUserId(long userId) {
		try {
			this.getSqlMapClientTemplate().getSqlMapClient().delete("EvtDAO.deleteEvtByUserId", userId);
		} catch (SQLException e) {
			log.error(e);
		}		
	}

	public void detelteEvtByCreateTime(Date datetime) {
		try {
			this.getSqlMapClientTemplate().getSqlMapClient().delete("EvtDAO.deleteEvtByCreateTime", datetime);
		} catch (SQLException e) {
			log.error(e);
		}		
	}
	
}
